﻿using System;
using System.Windows.Forms;

namespace Useful.GUI
{
    public class SimpleOptionalDateTimePicker : DateTimePicker
    {
        public SimpleOptionalDateTimePicker()
        {
            base.ShowCheckBox = true;
            base.Width = base.Width - 50;
        }

        public new DateTime? Value
        {
            get
            {
                return base.Checked ? (DateTime?)base.Value : null;
            }
            set
            {
                if (value != null)
                {
                    base.Value = value.Value;
                    base.Checked = true;
                }
                else
                {
                    base.Checked = false;
                }
            }
        }

        public DateTime? Date
        {
            get
            {
                return base.Checked ? (DateTime?)base.Value.Date : null;
            }
        }
    }
}